<?php

namespace App\Enums;

/**
 * 库存变动表单据类型枚举
 */
enum InvTransDocType: int
{
    case PURCHASE_RECEIPT           = 10; // 采购入库单
    case TEMPORARY_RECEIPT_RECEIPT  = 20; // 暂收入库单
    case SUBCONTRACTING_RECEIPT     = 30; // 委外入库
    case PRODUCTION_RETURN          = 40; // 生产退料单
    case PRODUCTION_RECEIPT         = 50; // 生产入库单
    case OTHER_RECEIPT              = 60; // 其他入库
    case SALES_DELIVERY             = 70; // 销售出库
    case PRODUCTION_PICKING         = 80; // 生产领料
    case OTHER_DELIVERY             = 90; // 其他出库
    case PRODUCTION_WORK_ORDERS     = 100; // 生产工单
    case TRANSFER_ORDER             = 110; // 调拨单
    case INVENTORY_ORDER            = 115; // 盘点单
    case PURCHASE_RECEIPT_RETURN    = 101; // 采购退货
    case SALES_DELIVERY_RECEIPT    = 140; // 销售退货
    case OTHER_RECEIPT_OTHOR    = 120; // 其他入库（盘点库存调整）
    case OTHER_DELIVERY_OTHOR   = 180; // 其他出库（盘点库存调整）
    case PURCHASE_RECEIPT_TISSUE   = 1000; // 组织间采购入库单
    case PURCHASE_RECEIPT_RETURN_TISSUE   = 10001; // 组织间采购退货
    case SALES_DELIVERY_TISSUE   = 701; // 组织间销售出库
    case SALES_DELIVERY_RECEIPT_TISSUE   = 141; // 组织间销售退货
    case DASSEMBLY_ASSEMBLY_ORDER   = 150; // 组装拆卸单

    /**
     * 获取名称
     * @return string
     */
    public function label(): string
    {
        return match ($this) {
            self::PURCHASE_RECEIPT          => "采购入库单",
            self::TEMPORARY_RECEIPT_RECEIPT => "暂收入库单",
            self::SUBCONTRACTING_RECEIPT    => "委外入库",
            self::PRODUCTION_RETURN         => "生产退料单",
            self::PRODUCTION_RECEIPT        => "生产入库单",
            self::OTHER_RECEIPT             => "其他入库",
            self::SALES_DELIVERY            => "销售出库",
            self::PRODUCTION_PICKING        => "生产领料",
            self::OTHER_DELIVERY            => "其他出库",
            self::PRODUCTION_WORK_ORDERS    => "生产工单",
            self::TRANSFER_ORDER            => "调拨单",
            self::INVENTORY_ORDER           => "盘点单",
            self::PURCHASE_RECEIPT_RETURN   => "采购退货",
            self::SALES_DELIVERY_RECEIPT   => "销售退货",
            self::OTHER_RECEIPT_OTHOR   => "其他入库（盘点库存调整）",
            self::OTHER_DELIVERY_OTHOR   => "其他出库（盘点库存调整）",
            self::PURCHASE_RECEIPT_TISSUE   => "组织间采购入库单",
            self::PURCHASE_RECEIPT_RETURN_TISSUE   => "组织间采购退货",
            self::SALES_DELIVERY_TISSUE   => "组织间销售出库",
            self::SALES_DELIVERY_RECEIPT_TISSUE   => "组织间销售退货",
            self::DASSEMBLY_ASSEMBLY_ORDER   => "组装拆卸单",
        };
    }

    /**
     * 根据值获取名称
     * @param $val
     * @return string
     */
    static function labelBy($val){
        $obj = self::tryFrom((int) $val);
        return $obj ? $obj->label() : '';
    }
}
